﻿#include "queue.h"

// 初始化头结点
Queue* create_queue() {
	Queue* head = (Queue*)malloc(sizeof(Queue));
	head->next = NULL;
	return head;
}
// 入队
void push(Queue* head, struct exam* data) {
	Queue* newNode = (Queue*)malloc(sizeof(Queue));
	newNode->content.data1 = data->data1;
	newNode->content.data2 = data->data2;
	Queue* p = head;
	while (p->next != NULL) {
		p = p->next;
	}

	p->next = newNode;
	newNode->next = NULL;
	p = newNode;
}
// 获取队列头的第一个数据
int front(Queue* head) {
	if (head->next == NULL) {
		printf("Queue is empty\n");
		return -1;
	}
	printf("当前队列中第一个数据是：%d\t", head->next->content.data1);
	printf("%d\n", head->next->content.data2);
	return 0;
}
// 出队
void pop(Queue* head) {
	if (head->next == NULL) {
		printf("队列是空的!\n");
		return;
	}
	Queue* p = head->next;
	head->next = head->next->next;
	free(p);
}
// 返回队列的大小
int size(Queue* head) {
	int count = 0;
	Queue* p = head->next;
	while (p != NULL) {
		count++;
		p = p->next;
	}
	return count;
}

// 判断队列是否为空
int isempty(Queue* head) {
	return head->next == NULL; 
}

// 销毁队列
void destroy_queue(Queue* head) {
	Queue* p = head;
	while (p != NULL) {
		Queue* temp = p;
		p = p->next;
		free(temp);
	}
}
